﻿using SRB.Tg.Model;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SRB.Tg.Model
{
    public class ModelOper
    {
        public static PileCapParameter GetPileCapPara(string id,out DataRow row)
        {
            PileCapParameter para = new PileCapParameter();
            string sql = string.Format("select  * from t_cap_reinforcement where id='{0}'  and status=0 ", id);
            DataTable dt = MySqlHelper.ExecuteDataTable(sql, CommandType.Text);
            row = null;
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                row = dr;
                para.Id = dr["id"].ToString();
                para.Name = dr["configure_name"].ToString();
                if (!dr.IsNull("length"))
                    para.L = double.Parse(dr["length"].ToString());
                if (!dr.IsNull("width"))
                    para.W = double.Parse(dr["width"].ToString());
                if (!dr.IsNull("height"))
                    para.H = double.Parse(dr["height"].ToString());
                if (!dr.IsNull("concrete_protect_layer"))
                    para.Cover = double.Parse(dr["concrete_protect_layer"].ToString());
                if (!dr.IsNull("bottom_l_reinforcement_spacing"))
                    para.t2bSapceL = int.Parse( dr["bottom_l_reinforcement_spacing"].ToString());
                if (!dr.IsNull("bottom_w_reinforcement_spacing"))
                    para.t2bSapceW = int.Parse(dr["bottom_w_reinforcement_spacing"].ToString());
                if (!dr.IsNull("around_reinforcement_spacing"))
                    para.sideSapce = int.Parse(dr["around_reinforcement_spacing"].ToString());
                if (!dr.IsNull("around_h_reinforcement_spacing"))
                    para.sideSapceH = int.Parse(dr["around_h_reinforcement_spacing"].ToString());
                if (!dr.IsNull("pile_penetration_depth"))
                    para.pileDepth = double.Parse(dr["pile_penetration_depth"].ToString());
                if (!dr.IsNull("structure_number"))
                    para.structureNumber = int.Parse(dr["structure_number"].ToString());
                if (!dr.IsNull("horizontal_support_reinforcement_spacing"))
                    para.vSp = dr["horizontal_support_reinforcement_spacing"].ToString();
                if (!dr.IsNull("erection_reinforcement_spacing"))
                    para.eSp = dr["erection_reinforcement_spacing"].ToString();
                if (!dr.IsNull("bottom_l_reinforcement_diameter"))
                    para.N1 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["bottom_l_reinforcement_diameter"].ToString());
                if (!dr.IsNull("bottom_w_reinforcement_diameter"))
                    para.N2 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["bottom_w_reinforcement_diameter"].ToString());
                if (!dr.IsNull("top_l_reinforcement_diameter"))
                    para.N3 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["top_l_reinforcement_diameter"].ToString());
                if (!dr.IsNull("top_w_reinforcement_diameter"))
                    para.N4 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["top_w_reinforcement_diameter"].ToString());
                if (!dr.IsNull("around_h_reinforcement_diameter"))
                    para.N5 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["around_h_reinforcement_diameter"].ToString());
                if (!dr.IsNull("around_l_reinforcement_diameter"))
                    para.N6 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["around_l_reinforcement_diameter"].ToString());
                if (!dr.IsNull("around_w_reinforcement_diameter"))
                    para.N7 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["around_w_reinforcement_diameter"].ToString());
                if (!dr.IsNull("erection_reinforcement_diameter"))
                    para.N8 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["erection_reinforcement_diameter"].ToString());
                if(!dr.IsNull("horizontal_support_l_reinforcement_diameter"))
                 para.N9 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["horizontal_support_l_reinforcement_diameter"].ToString());
                if (!dr.IsNull("horizontal_support_w_reinforcement_diameter"))
                    para.N10 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["horizontal_support_w_reinforcement_diameter"].ToString());
                if (!dr.IsNull("reinforcement_net_l_diameter"))
                    para.N11 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["reinforcement_net_l_diameter"].ToString());
                if (!dr.IsNull("reinforcement_net_w_diameter"))
                    para.N12 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["reinforcement_net_w_diameter"].ToString());
                if (!dr.IsNull("reinforcement_net_l_spacing"))
                    para.netSpacingL = int.Parse(dr["reinforcement_net_l_spacing"].ToString());
                if (!dr.IsNull("reinforcement_net_w_spacing"))
                    para.netSpacingW = int.Parse(dr["reinforcement_net_w_spacing"].ToString());
                if (!dr.IsNull("bottom_reinforcement_layers_number"))
                    para.bottomNum = int.Parse(dr["bottom_reinforcement_layers_number"].ToString());
                if (!dr.IsNull("top_reinforcement_layers_number"))
                    para.topNum = int.Parse(dr["top_reinforcement_layers_number"].ToString());
            }
            return para;
        }

        public static PlinthParameter GetPlinthPara(string id, out DataRow row)
        {
            PlinthParameter para = new PlinthParameter();
            string sql = string.Format("select  * from t_cushion_stone where id='{0}'  and status=0 ", id);
            DataTable dt = MySqlHelper.ExecuteDataTable(sql, CommandType.Text);
            row = null;
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                row = dr;
                para.Id = dr["id"].ToString();
                para.Name = dr["configure_name"].ToString();
                if (!dr.IsNull("length"))
                    para.L = double.Parse(dr["length"].ToString());
                if (!dr.IsNull("width"))
                    para.W = double.Parse(dr["width"].ToString());
                if (!dr.IsNull("height"))
                    para.H = double.Parse(dr["height"].ToString());
                if (!dr.IsNull("concrete_protect_layer"))
                    para.Cover = double.Parse(dr["concrete_protect_layer"].ToString());
                if (!dr.IsNull("structure_number"))
                    para.structureNumber = int.Parse(dr["structure_number"].ToString());
                if (!dr.IsNull("main_l_reinforcement_diameter"))
                    para.N1 = (eRebarDia)Enum.Parse(typeof(eRebarDia),dr["main_l_reinforcement_diameter"].ToString());
                if (!dr.IsNull("main_l_reinforcement_diameter"))
                    para.N2 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["main_w_reinforcement_diameter"].ToString());
                if (!dr.IsNull("main_l_reinforcement_diameter"))
                    para.N3 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["reinforcement_net_diameter"].ToString());
                if (!dr.IsNull("main_l_reinforcement_diameter"))
                    para.N4 = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["reinforcement_net_diameter"].ToString());
                if (!dr.IsNull("main_l_reinforcement_spacing"))
                    para.sapceL = int.Parse(dr["main_l_reinforcement_spacing"].ToString());
                if (!dr.IsNull("main_w_reinforcement_spacing"))
                    para.sapceW = int.Parse(dr["main_w_reinforcement_spacing"].ToString());
                if (!dr.IsNull("reinforcement_net_spacing"))
                    para.NetSapce = int.Parse(dr["reinforcement_net_spacing"].ToString());
                if (!dr.IsNull("reinforcement_net_layers_number"))
                    para.NetNumber = int.Parse(dr["reinforcement_net_layers_number"].ToString());
            }
            return para;
        }

        public static PileParameter GetPilePara(string id, out DataRow row)
        {
            PileParameter para = new PileParameter();
            string sql = string.Format("select  * from t_pile_reinforcement where id='{0}'  and status=0 ", id);
            DataTable dt = MySqlHelper.ExecuteDataTable(sql, CommandType.Text);
            row = null;
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                row = dr;
                para.Id = dr["id"].ToString();
                para.Name = dr["configure_name"].ToString();    
                if (!dr.IsNull("concrete_no"))
                    para.concreteNo = dr["concrete_no"].ToString();
                if (!dr.IsNull("reinforcement_grade"))
                    para.reinforcementGrade = dr["reinforcement_grade"].ToString();
                if (!dr.IsNull("structure_number"))
                    para.structureNumber = int.Parse(dr["structure_number"].ToString());
                if (!dr.IsNull("main_reinforcement_diameter"))
                    para.main_reinforcement_diameter = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["main_reinforcement_diameter"].ToString());
                if (!dr.IsNull("main_reinforcement_number"))
                    para.main_reinforcement_number = int.Parse(dr["main_reinforcement_number"].ToString());
                if (!dr.IsNull("spiral_reinforcement_diameter"))
                    para.spiral_reinforcement_diameter = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["spiral_reinforcement_diameter"].ToString());              
                if (!dr.IsNull("top_encryption_length"))
                    para.top_encryption_length = double.Parse(dr["top_encryption_length"].ToString());
                if (!dr.IsNull("top_encryption_spacing"))
                    para.top_encryption_spacing = double.Parse(dr["top_encryption_spacing"].ToString());
                if (!dr.IsNull("bottom_encryption_length"))
                    para.bottom_encryption_length = double.Parse(dr["bottom_encryption_length"].ToString());
                if (!dr.IsNull("bottom_encryption_spacing"))
                    para.bottom_encryption_spacing = double.Parse(dr["bottom_encryption_spacing"].ToString());
                if (!dr.IsNull("outer_strengthen_reinforcement_diameter"))
                    para.outer_strengthen_reinforcement_diameter = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["outer_strengthen_reinforcement_diameter"].ToString());
                if (!dr.IsNull("outer_strengthen_reinforcement_spacing"))
                    para.outer_strengthen_reinforcement_spacing = double.Parse(dr["outer_strengthen_reinforcement_spacing"].ToString());
                if (!dr.IsNull("inner_strengthen_reinforcement_diameter"))
                    para.inner_strengthen_reinforcement_diameter = (eRebarDia)Enum.Parse(typeof(eRebarDia), dr["inner_strengthen_reinforcement_diameter"].ToString());
                if (!dr.IsNull("inner_strengthen_reinforcement_spacing"))
                    para.inner_strengthen_reinforcement_spacing = double.Parse(dr["inner_strengthen_reinforcement_spacing"].ToString());
                if (!dr.IsNull("top_reinforcement_diameter"))
                    para.top_reinforcement_diameter = double.Parse(dr["top_reinforcement_diameter"].ToString());
                if (!dr.IsNull("top_reinforcement_number"))
                    para.top_reinforcement_number = int.Parse(dr["top_reinforcement_number"].ToString());
                if (!dr.IsNull("acoustic_tube_type"))
                    para.acoustic_tube_type = dr["acoustic_tube_type"].ToString();
                if (!dr.IsNull("acoustic_tube_number"))
                    para.acoustic_tube_number = int.Parse(dr["acoustic_tube_number"].ToString());
                if (!dr.IsNull("pile_length"))
                    para.pile_length = double.Parse(dr["pile_length"].ToString());
                if (!dr.IsNull("pile_diameter"))
                    para.pile_diameter = double.Parse(dr["pile_diameter"].ToString());
                if (!dr.IsNull("standard_spacing"))
                    para.standard_spacing = double.Parse(dr["standard_spacing"].ToString());
                if (!dr.IsNull("bottom_distance"))
                    para.bottom_distance = double.Parse(dr["bottom_distance"].ToString());
                if (!dr.IsNull("pile_penetration_depth"))
                    para.pile_penetration_depth = double.Parse(dr["pile_penetration_depth"].ToString());
                if (!dr.IsNull("concrete_protect_layer"))
                    para.concreteProtectLayer = double.Parse(dr["concrete_protect_layer"].ToString());
                if (!dr.IsNull("top_size"))
                    para.top_size = dr["top_size"].ToString();
                if (!dr.IsNull("bottom_size"))
                    para.bottom_size = dr["bottom_size"].ToString();
            }
            return para;
        }
    }
}
